﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BEX.Core.Exchange.MTGOXWebSocket
{
    public class MtGoxTicker
    {
        /*
        private int _last;

        public int Last
        {
            get
            {
                return _last;
            }
        }

        private int _ask;

        public int Ask
        {
            get
            {
                return _ask;
            }
        }

        private int _bid;

        public int Bid
        {
            get
            {
                return _bid;
            }
        }

        private CurrencyType _baseCurrency;

        public CurrencyType BaseCurrency
        {
            get
            {
                return _baseCurrency;
            }
        }

        private CurrencyType _counterCurrency;

        public CurrencyType CounterCurrency
        {
            get
            {
                return _counterCurrency;
            }
        }

        private UInt64 _unixTime;

        public UInt64 UnixTime
        {
            get
            {
                return _unixTime;
            }
        }

        public DateTime Time { get; set; }

        private string _message;

        public string Message
        {
            get
            {
                return _message;
            }
        }

        public MtGoxTicker(string source)
        {
            ParseNew(source);
        }
               private void ParseNew(string s)
        {
            var _findBuy = false;
            var _findSell = false;
            var _findLast = false;


            var _m = s.Split(',');


            foreach (string _s in _m)
            {
                if (_s.Contains("\"last\":{"))
                {
                    _findLast = true;
                    continue;
                }

                if (_s.Contains("\"buy\":{"))
                {
                    _findBuy = true;
                    continue;
                }

                if (_s.Contains("\"sell\":{"))
                {
                    _findSell = true;
                    continue;
                }

                if (_s.Contains("ticker."))
                {
                    var _r = _s.Split(':');

                    _r[1] = _r[1].Replace("\"", string.Empty).Replace(",", string.Empty).Replace("ticker.", string.Empty).Trim();

                    _baseCurrency = TradeCurrency.GetCurrencyType(_r[1].Substring(0, 3));

                    _counterCurrency = TradeCurrency.GetCurrencyType(_r[1].Substring(3));

                    continue;
                }

                if (_findSell)
                {
                    if (_s.Contains("value_int"))
                    {
                        var _r = _s.Split(':');

                        _r[1] = _r[1].Replace("\"", string.Empty).Replace(",", string.Empty).Trim();

                        _bid = Convert.ToInt32(_r[1]);

                        _findSell = false;
                    }
                }

                if (_findLast)
                {
                    if (_s.Contains("value_int"))
                    {
                        var _r = _s.Split(':');

                        _r[1] = _r[1].Replace("\"", string.Empty).Replace(",", string.Empty).Trim();

                        _last = Convert.ToInt32(_r[1]);

                        _findLast = false;
                    }
                }

                if (_findBuy)
                {
                    if (_s.Contains("value_int"))
                    {
                        var _r = _s.Split(':');

                        _r[1] = _r[1].Replace("\"", string.Empty).Replace(",", string.Empty).Trim();

                        _ask = Convert.ToInt32(_r[1]);

                        _findBuy = false;
                    }
                }

                if (_s.Contains("now"))
                {
                    var _r = _s.Split(':');

                    _r[1] = _r[1].Replace("\"", string.Empty).Replace("}", string.Empty).Replace(",", string.Empty).Trim();

                    _unixTime = Convert.ToUInt64(_r[1]);
                }
            }
        }*/
    }
}
